package com.solming.leetcode.question;

import java.util.HashMap;
import java.util.List;

public class HasCycle141 {
    /**
     * 快慢指针的方式同样能够找到环的判断。
     * @param head
     * @return
     */
    public static boolean hasCycle(ListNode head) {
        HashMap<ListNode,Integer> indexMap = new HashMap<>();
        ListNode start = head;
        ListNode end = head;
        int i = 0;
        while (end != null && end.next != null) {
            start = start.next;
            end = end.next.next;
            if (start == end) {
                return true;
            }
        }
        return false;

    }

    public static void main(String[] args) {
        ListNode node = new ListNode(2,null);
        ListNode node1 = new ListNode(-4);
        node1.next = node;
        node.next = new ListNode(0,node1);
        ListNode head = new ListNode(3,node);

    }


}



